//
// Created by kyle on 25-7-15.
//

#ifndef UTIL_H
#define UTIL_H
#include <memory>

#include "FrameBuffer.h"
#include <string>
#include <iostream>
#include <fstream>
#include <string>
#include <string_view>
#include <system_error>
#include <filesystem>
#include <freetype/freetype.h>

#include "TextObject.h"

class Util {
public:
    /**
    *执行命令
    */
    static std::string exec_command(const std::string &cmd);

    /**
     * 字符转整型
     * @param str
     * @return
     */
    static int stringToIntStoi(const std::string &str);

    /**
     * 读取文件内容
     * @param path
     * @return
     */
    static std::string readFile(std::string_view path);

    /**
         * 读取文件内容
         * @param path
         * @return
         */
    static std::string readFileOrDefault(std::string_view path, std::string_view defaultValue);

    // 在后备缓冲区写入像素
    static void fb_write_pixel(const std::shared_ptr<FrameBuffer> &fb, int x, int y, unsigned char r, unsigned char g,
                               unsigned char b);

    // 填充矩形
    static void fb_fill_rect(const std::shared_ptr<FrameBuffer> &fb, int x, int y, int width, int height,
                             unsigned char r, unsigned char g, unsigned char b);

    // 将UTF-8字符串分割为Unicode字符向量
  static  std::vector<std::string> split_utf8(const std::string &str);

    /**
     * 获取最佳字体大小
     * @param screen_width
     * @param screen_height
     * @param font_radio
     * @param text
     * @return
     */
    static TextObject calculateBestFontSize(int screen_width, int screen_height, double font_radio, const std::string& text) ;
};


#endif //UTIL_H
